<%@ page import="java.util.Calendar" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="ru.niir.goodfil.ui.StorekeeperOrdersBean" %>
<%@ page import="ru.niir.goodfil.db.Order" %>
<%@page contentType="text/html" %>
<%@page pageEncoding="UTF-8" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@taglib prefix="a4j" uri="http://richfaces.org/a4j" %>
<%@taglib prefix="rich" uri="http://richfaces.org/rich" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Goodwill - Резервы</title>
    <link rel="stylesheet" href="resources/css/main.css"/>
</head>
<body>
    <f:view>

        <a4j:form id="jsForm" prependId="false">
            <a4j:jsFunction name="refresh" action="#{StorekeeperReservesBean.refresh}" limitToList="true"
                            oncomplete="document.location='reserves';"/>
        </a4j:form>

        <jsp:include page="StorageMenu.jsp"/>

        <h:panelGroup id="links" layout="block" styleClass="">
            <a4j:commandLink value="Обновить" onclick="refresh();" style="margin-top: 10px; margin-left: 10px; font-size: 1.5em;"/>
        </h:panelGroup>
            <h2 align="left">Резервы (не установлена дата отгрузки). Доступно только менеджеру и администратору</h2>



        <h:form>
            <rich:dataTable id="reservedOrder"
                            value="#{StorekeeperReservesBean.reservedOrders}"
                            rowKeyVar="row"
                            var="order"
                    >
                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="№"/>
                    </f:facet>
                    <h:outputText value="#{row + 1}. "/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Номер ИС"/>
                    </f:facet>
                    <h:outputText value="#{order.id}" style="#{order.reservationDateIsInPast ? 'color:red':''}"/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Счет 1С"/>
                    </f:facet>
                    <h:outputText value="#{order.c1Num}" style="#{order.reservationDateIsInPast ? 'color:red':''}"/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Дата создания"/>
                    </f:facet>
                    <h:outputText value="#{order.creationDateAsString}" style="#{order.reservationDateIsInPast ? 'color:red':''}"/>
                </rich:column>

                <rich:column >
                    <f:facet name="header">
                        <h:outputText value="Менеджер"/>
                    </f:facet>
                    <h:outputText value="#{order.manager.fio}" style="#{order.reservationDateIsInPast ? 'color:red':''}"/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Клиент"/>
                    </f:facet>
                    <h:outputText value="#{order.client.companyName}" style="#{order.reservationDateIsInPast ? 'color:red':''}"/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Статус клиента"/>
                    </f:facet>
                    <h:outputText value="#{order.client.clientStateAsString}" style="#{order.reservationDateIsInPast ? 'color:red':''}"/>
                </rich:column>

                <rich:column sortable="true" sortBy="#{order.sum}">
                    <f:facet name="header">
                        <h:outputText value="Сумма заказа"/>
                    </f:facet>
                    <h:outputText value="#{order.sumAsString}" style="#{order.reservationDateIsInPast ? 'color:red':''}"/>
                </rich:column>
                <f:facet name="footer">
                    <rich:columnGroup>
                        <rich:column/>
                        <rich:column/>
                        <rich:column/>
                        <rich:column/>
                        <rich:column/>
                        <rich:column/>
                        <rich:column/>
                        <rich:column>
                            <h:outputText value="Итого: #{StorekeeperReservesBean.reservedOrdersSum}"/>
                        </rich:column>
                    </rich:columnGroup>
                </f:facet>
            </rich:dataTable>
        </h:form>

    </f:view>
</body>
</html>